package com.example.wufan.zyfypt_425wff.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wufan.zyfypt_425wff.R;
import com.example.wufan.zyfypt_425wff.iface.RegisterListener;
import com.example.wufan.zyfypt_425wff.model.RegisterModel;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tv1,tvname,tvi,tvl,tvage,tvpw,tvname1,tvpw2,tvph;
    private Button b0,bp,bb;
    private EditText et1,et2,et3,et4,et5;
    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                finish();
            }else{
                System.out.println("result:"+msg);
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        init();
    }
    private void init(){

        tvname=(TextView)findViewById(R.id.textView18);
        tvi=(TextView)findViewById(R.id.textView20);
        tvl=(TextView)findViewById(R.id.textView7);
        tvage=(TextView)findViewById(R.id.textView16);
        tvpw=(TextView)findViewById(R.id.textView12);
        tvname1=(TextView)findViewById(R.id.textView10);
        tvpw2=(TextView)findViewById(R.id.textView15);
        tvph=(TextView)findViewById(R.id.textView17);
        et1=(EditText)findViewById(R.id.editText);
        et2=(EditText)findViewById(R.id.editText2);
        et3=(EditText)findViewById(R.id.editText3);
        et5=(EditText)findViewById(R.id.editText4);
        et4=(EditText)findViewById(R.id.editText5);
        b0=(Button)findViewById(R.id.button3);
        bp=(Button)findViewById(R.id.button5);
        bb=(Button)findViewById(R.id.button4);

        b0.setOnClickListener(this);
        bp.setOnClickListener(this);
        bb.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
            switch (v.getId()) {
                case R.id.button4:
                    finish();
                    Intent intent = new Intent(RegisterActivity.this,LoginActivity.class);
                    startActivity(intent);
                    System.out.println("注册——提交");
                    RegisterModel registerModel = new RegisterModel();
                    registerModel.getResult(et1.getText().toString(),
                            et2.getText().toString(),
                            et3.getText().toString(), registerListener);

                    break;
                case R.id.button5:
                    finish();
                    intent = new Intent(RegisterActivity.this,LoginActivity.class);
                    startActivity(intent);

                    break;
            }

        }

    }


